<%--
  Created by IntelliJ IDEA.
  User: JesseChan
  Date: 2022/5/10
  Time: 21:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.biejiaogroup.librarymanager.entity.User" %>
<html>
<head>
    <title>图书管理系统</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css">
    <link href="css/style.css" rel="stylesheet">
    <script type="text/javascript" src="js/jquery-3.6.0.js"></script>
    <script type="text/javascript" src="js/bootstrap.bundle.js"></script>
</head>
<body class="gray-bg">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <a class="navbar-brand" href="admin.jsp">图书管理系统</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup"
            aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="topNavBar">
        <div class="navbar-nav">
            <a class="nav-link" href="mainPage.jsp">主页</a>
            <%
                User user = (User) session.getAttribute("user");
                if (user != null)
                {
                    if (user.getUserLevel() == 0)
                    {
                        out.println("<a class=\"nav-link\" href=\"userManager.jsp\">用户信息管理</a>");
                        out.println("<a class=\"nav-link\" href=\"bookManager.jsp\">图书管理</a>");
                    }
                    else
                    {
                        out.println("<a class=\"nav-link\" href=\"user.jsp\">个人中心</a>");
                    }
                }
            %>
        </div>
    </div>

    <input id="presentUserID" style="visibility: hidden" value="${user.userID}"></input>
    <%
        //登录按钮
        if (session.getAttribute("login") != null)
        {
            if (user.getUserLevel() == 0) out.println("<td>欢迎管理员" + user.getUserName() + "</td>");
            else out.println("<td>欢迎" + user.getUserName() + "</td>");
            out.println("<div class=\"navbar-form navbar-right\">\n" +
                    "        <button class=\"btn btn-outline-danger my-2 my-sm-0\" type=\"button\" data-toggle=\"modal\" data-target=\"#exitModal\">退出登录</button>\n" +
                    "    </div>");
        }
        else
        {
            out.println("<div class=\"navbar-form navbar-right\">\n" +
                    "        <button class=\"btn btn-outline-success my-2 my-sm-0\" type=\"button\" data-toggle=\"modal\" data-target=\"#loginModal\">Login</button>\n" +
                    "    </div>");
        }
    %>
</nav>

<div id="exitModal" class="modal fade" aria-hidden="true" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">确定要退出吗？</h4>
            </div>
            <div class="modal-body">
                <form class="m-t" role="form">
                    <button type="button" class="btn btn-sm btn-danger float-right m-t-n-xs" id="btn_confirm_logout">
                        退出
                    </button>
                </form>
            </div>

        </div>
    </div>
</div>


</body>

<script>
    $("#btn_login").click(function () {
        $.ajax({
            data: {
                "adminName": $("#adminName").val(),
                "adminPassword": $("#adminPassword").val(),
            },
            "type": "post",
            "url": "adminLogin",


        });
    });

    //退出登录
    $("#btn_confirm_logout").click(function () {
        $.ajax({
            url: "logout",
            type: "post",
            success: function (data) {
                if (data == "success") {
                    window.location.href = "index.jsp";
                } else {
                    alert("退出失败");
                }
            }
        });
    });

</script>
</html>
